home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_traceback.py < prev    next >
Text File  |  2005-11-19  |  2KB  |  50 lines

  1. """Test cases for traceback module"""
  2.  
  3. import unittest
  4. from test.test_support import run_unittest, is_jython
  5.  
  6. import traceback
  7.  
  8. class TracebackCases(unittest.TestCase):
  9.     # For now, a very minimal set of tests.  I want to be sure that
  10.     # formatting of SyntaxErrors works based on changes for 2.1.
  11.  
  12.     def get_exception_format(self, func, exc):
  13.         try:
  14.             func()
  15.         except exc, value:
  16.             return traceback.format_exception_only(exc, value)
  17.         else:
  18.             raise ValueError, "call did not raise exception"
  19.  
  20.     def syntax_error_with_caret(self):
  21.         compile("def fact(x):\n\treturn x!\n", "?", "exec")
  22.  
  23.     def syntax_error_without_caret(self):
  24.         # XXX why doesn't compile raise the same traceback?
  25.         import test.badsyntax_nocaret
  26.  
  27.     def test_caret(self):
  28.         err = self.get_exception_format(self.syntax_error_with_caret,
  29.                                         SyntaxError)
  30.         self.assert_(len(err) == 4)
  31.         self.assert_("^" in err[2]) # third line has caret
  32.         self.assert_(err[1].strip() == "return x!")
  33.  
  34.     def test_nocaret(self):
  35.         if is_jython:
  36.             # jython adds a caret in this case (why shouldn't it?)
  37.             return
  38.         err = self.get_exception_format(self.syntax_error_without_caret,
  39.                                         SyntaxError)
  40.         self.assert_(len(err) == 3)
  41.         self.assert_(err[1].strip() == "[x for x in x] = x")
  42.  
  43.  
  44. def test_main():
  45.     run_unittest(TracebackCases)
  46.  
  47.  
  48. if __name__ == "__main__":
  49.     test_main()
  50.